$(function() {
    (function ($) {
        $.getUrlParam = function (name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
    })(jQuery);

    var contextPath = function() {
        return  "/" + location.pathname.split("/")[1];
    }

    function getValue(name){
        var str=window.location.search;
        if (str.indexOf(name)!=-1){
            var pos_start=str.indexOf(name)+name.length+1;
            var pos_end=str.indexOf("&",pos_start);
            if (pos_end==-1){
                return str.substring(pos_start);
            } else {
                return str.substring(pos_start,pos_end);
            }
        } else {
            return "";
        }
    }

    var  themeName = getValue("theme");
    if (themeName!=""){
        var cssurl  = $('#easyuiTheme').attr('href');
        var href = cssurl.substring(0, cssurl.indexOf('themes')) + 'themes/' + themeName + '/easyui.css';
        $('#easyuiTheme').attr('href', href);
    }
    var courseid = $.getUrlParam('courseid');


	getContext();
	
	function getContext(e) {
		$.ajax({
			url : contextPath()+"/airuc/getcoursebyid?courseid="+courseid,
			type : "get",
			dataType : "json",
			success : function(data) {
				if (data.success) {
					createPage(data.course);
				}
			}
		});
	}
	
	function createPage(data) {
		var html = '';
			html += "<div class='weui-panel weui-panel_access'>"
					+ "<div class='weui-panel__hd'><h1>"+data.courseName+"</h1></div>"
					+ "<div class='weui-panel__bd'>";
		data.lessonList.map(function(item1, index1) {
				html += "<a href='yylesson.html?lessonid="+item1.lessonID+"' class='weui-media-box weui-media-box_appmsg'>"
	    		+ "<div class='weui-media-box__hd'>"
	    		+ "<img class='weui-media-box__thumb' src='"+item1.lessonImg+"'>"
	    		+ "</div>"
	    		+ "<div class='weui-media-box__bd'>"
	    		+ "<h4 class='weui-media-box__title'>"+item1.lessonName+"</h4>"
	    		+ "<p class='weui-media-box__desc'>"+item1.lessonDesc+"</p>"
	    		+ "</div>"
	    		+ "</a>";
		});
		html += "</div>";
		html += "</div>";
			//绘制底线
		html += "<div class='weui-loadmore weui-loadmore_line'><span class='weui-loadmore__tips'>我是有底线的</span></div>";
		$('#tab1').html(html);
	}
    
});


